package work;

import org.apache.commons.lang.StringUtils;

import java.util.Arrays;

public class InListDemo {
    public static void main(String[] args) {
        System.out.printf("%s:%s\n", false, isInList("", ""));
        System.out.printf("%s:%s\n", false, isInList(null, ""));
        System.out.printf("%s:%s\n", false, isInList("", null));
        System.out.printf("%s:%s\n", false, isInList("abcd", null));
        System.out.printf("%s:%s\n", true, isInList("abcd", "ab,cd"));
        System.out.printf("%s:%s\n", true, isInList("abcd", "a"));
        System.out.printf("%s:%s\n", true, isInList("abcd", "D"));
        System.out.printf("%s:%s\n", false, isInList("abcd", ","));
        System.out.printf("%s:%s\n", true, isInList("abcd", ",b"));
        System.out.printf("%s:%s\n", true, isInList("abcd", "a"));
        System.out.printf("%s:%s\n", false, isInList("abcd", "  ,  "));
    }

    public static boolean isInList(String stbid, String idList) {
        if (StringUtils.isBlank(stbid) || StringUtils.isBlank(idList)) {
            System.out.println("stbid = [" + stbid + "], idList = [" + idList + "] [WARN ] 名单或STBID为空！");
            return false;
        }
        String[] list = idList.split(",");
        for (String id : list) {
            if (StringUtils.containsIgnoreCase(stbid, id)) {
                return true;
            }
        }
                return false;
                }


}
